use lazy_static::lazy_static;
use rbase::db::DbColumnDefine;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "t_classroom")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,

    #[sea_orm(default_value = 0)]
    pub owner_id: Option<i64>,

    #[sea_orm(default_value = "")]
    pub grade: Option<String>,

    #[sea_orm(default_value = "")]
    pub class: Option<String>,

    #[sea_orm(default_value = "")]
    pub name: Option<String>,

    #[sea_orm(default_value = 0)]
    pub created_at: Option<i64>,

    #[sea_orm(default_value = 0)]
    pub modified_at: Option<i64>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation, Deserialize, Serialize)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {} // 必须实现这个trait

pub static TABLE_NAME: &str = "t_classroom";
pub static CREATE_QUERY: &str = r#"
    CREATE TABLE IF NOT EXISTS t_classroom (
        id              INTEGER NOT NULL PRIMARY KEY,
        owner_id        INTEGER     NOT NULL,
        grade           TEXT        NOT NULL,
        class           TEXT        NOT NULL,
        name            TEXT        NOT NULL,
        created_at      INTEGER     NOT NULL,
        modified_at     INTEGER     NOT NULL
    );
"#;

lazy_static! {
    pub static ref TABLE_COLUMNS: Vec<DbColumnDefine<'static>> = vec![];
}

pub fn get_column(name: &String) -> Column {
    match name.as_str() {
        "id" => Column::Id,
        "owner_id" => Column::OwnerId,
        "grade" => Column::Grade,
        "class" => Column::Class,
        "name" => Column::Name,
        "created_at" => Column::CreatedAt,
        "modified_at" => Column::ModifiedAt,
        _ => Column::Id,
    }
}
